package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "C端购物车接口")
public class ShoppingCarController {
    @Autowired
    ShoppingCarService service;

    /**
     * 购物车添加方法
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        service.add(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 购物车查看
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("购物车查看")
    public Result <List<ShoppingCart> >select(){
        List<ShoppingCart> list = service.select();
        return Result.success(list);
    }


    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result deleteAll(){

        service.deleteAll();
        return Result.success();
    }

    /**
     * 减少购物车的份数
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/sub")
    @ApiOperation("减少购物车的份数")
    public Result deleteOne(@RequestBody ShoppingCartDTO shoppingCartDTO){
        service.deleteOne(shoppingCartDTO);
        return Result.success(shoppingCartDTO);
    }


}
